package com.woniuxy.test_file;

import java.io.File;

/**
 * description: PrintFileTree <br>
 * date: 2022/2/2 2:29 下午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */
//递归打印目录结构树

public class PrintFileTree {
    public static void main(String[] args) {
        File f = new File("/Users/shesaifei/软件安装配置/");
        printFile(f, 0);
    }

    static void printFile(File file, int level) {
        //输出层数
        for (int i = 0; i < level; i++) {
            System.out.println("-");
        }
        System.out.println(file.getName());
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File temp : files) {
                printFile(temp, level + 1);
            }
        }
    }
}
